import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

public class SolutionLCP9 {
    public int minJump(int[] jump) {
        int[] visit=new int[jump.length];
        Arrays.fill(visit,-1);
        visit[0]=0;
        int now=0;
        int ans=Integer.MAX_VALUE;
        Queue<Integer> queue=new LinkedList<>();
        queue.offer(0);
        while (!queue.isEmpty()){
            int v=queue.poll();
            while (now<=v){
                if (visit[now]==-1 || visit[now]>visit[v]+1){
                    visit[now]=visit[v]+1;
                    queue.offer(now);
                }
                now++;
            }
            if (jump[v]+v>=jump.length){
                ans=Math.min(ans,visit[v]+1);
            }else {
                if (visit[jump[v]+v]==-1 || visit[jump[v]+v]>visit[v]+1){
                    visit[jump[v]+v]=visit[v]+1;
                    queue.offer(jump[v]+v);
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionLCP9().minJump(new int[]{2,5,1,1,1,1}));
    }
}
